package com.ea.admin.service.impl;

import com.ea.admin.mapper.AdminRoleMapper;
import com.ea.admin.service.MysqlConfigService;
import com.ea.common.result.BizException;
import com.ea.common.result.ErrorCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MysqlConfigServiceImpl implements MysqlConfigService {
    @Resource
    AdminRoleMapper testMapper;

    @Override
    public void testConnection(String url, String username, String password) {
        //修改数据库连接信息
        try {
            // 同步保证并发安全
            synchronized (this) {
                //执行测试sql
                testMapper.selectById(1);
            }
        } catch (Exception e) {
            throw new BizException(ErrorCode.SYSTEM_ERROR_EDIT_MYSQL_CONFIG_ERROR);
        }
    }
}
